/**
 *  CHMsgSendListener.mm
 *  @author Nick Kreeger <nick.kreeger@park.edu>
 */

#include "CHMsgSendListener.h"
#import "NSString+Utils.h"
#import <Foundation/Foundation.h>

NS_IMPL_ISUPPORTS2(CHMsgSendListener, nsIMsgSendListener, nsIMsgProgress);

CHMsgSendListener::CHMsgSendListener()
{
  NSLog(@"*********** Creating a CHMsgSendListener\n");
}

CHMsgSendListener::~CHMsgSendListener()
{
  NSLog(@"*********** Destroying a CHMsgSendListener\n");
  //XXX make sure we are getting destroyed...
}

void 
CHMsgSendListener::SetProgressDelegate(id<MessageSendListener> aProgressDelegate)
{
  mProgressDelgate = aProgressDelegate;
}

NS_IMETHODIMP 
CHMsgSendListener::OnStartSending(const char* aMsgID, PRUint32 aMsgSize)
{
  NSLog(@"*********** ::OnStartSending()\n");
  [mProgressDelgate onStartSending];
  return NS_OK;
}

NS_IMETHODIMP 
CHMsgSendListener::OnProgress(const char* aMsgID, PRUint32 aProgress, PRUint32 aProgressMax)
{
  NSLog(@"*********** ::OnProgress()\n");
  [mProgressDelgate onProgress:aProgress maxProgress:aProgressMax];
  return NS_OK;
}

NS_IMETHODIMP 
CHMsgSendListener::OnStatus(const char* aMsgID, const PRUnichar* aMsg)
{
  NSLog(@"*********** OnStatus()\n");
  [mProgressDelgate onStatus:[NSString stringWithPRUnichars:aMsg]];
  return NS_OK;
}

NS_IMETHODIMP 
CHMsgSendListener::OnStopSending(const char* aMsgID, 
                                 nsresult aStatus,
                                 const PRUnichar* aMsg,
                                 nsIFileSpec* returnFileSpec)
{
  NSLog(@"*********** OnStopSending()\n");
  [mProgressDelgate onStopSending:[NSString stringWithPRUnichars:aMsg]];
  return NS_OK;
}

NS_IMETHODIMP 
CHMsgSendListener::OnGetDraftFolderURI(const char* aFolderURI)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP 
CHMsgSendListener::OnSendNotPerformed(const char* aMsgID, nsresult aStatus)
{
  NSLog(@"*********** ::OnSendNotPerformed()\n");
  [mProgressDelgate onSendNotPerformed];
  return NS_OK;
}
